package junmo.s3caesar.mandu.nhkradionews.data;

import java.util.List;

import junmo.s3caesar.mandu.nhkradionews.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NewsAdapter extends BaseAdapter {
	
    private final Context context;
    private final List<News> newsList;
    
    private LayoutInflater inflater;

    public NewsAdapter(Context context, List<News> newsList) {
        this.context = context;
        this.newsList = newsList;
        
        inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

	@Override
	public int getCount() {
        return this.newsList.size();
	}

	@Override
	public Object getItem(int position) {
        return this.newsList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View v = inflater.inflate(R.layout.news_list_item, null);
		TextView title = (TextView) v.findViewById(R.id.news_list_view_title_id);
		TextView pubDate = (TextView) v.findViewById(R.id.news_list_view_pub_date_id);
        
		News news = this.newsList.get(position);
        title.setText(news.getTitle());
        title.setSelected(true);
        pubDate.setText(news.getPubDate());
        
        v.setOnClickListener(news);
        return v;
	}
	
}
